package com.ls.herostory.thread;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author liangsu
 * @version v1.0
 * @Description
 * @Date 2020/10/14 15:42
 * @since
 */
public class MyThreadFactory implements ThreadFactory {

    private AtomicInteger index = new AtomicInteger(0);
    private String threadName;

    public MyThreadFactory(String threadName) {
        this.threadName = threadName;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread t = new Thread(r);
        t.setName(threadName + "_"+ index.incrementAndGet());
        return t;
    }
}
